<template>
	<div class="subwindow">
		<!-- 侧边栏纵向布局 -->
		<div class="app-sidebar">
			<div class="has-logo">
				<el-image style="width: 30px; height: 30px" :src="logo"></el-image>
				<!-- <img v-if="logo" :src="logo" class="sidebar-logo"> -->
				<h1 class="sidebar-title" :title="title">{{ title }} V{{version}} </h1>
			</div>
			<div class="right-menu-btns">
				<i class="icon el-icon-minus" @click="minimizeFn"></i>
				<i class="icon el-icon-close" @click="closeFn"></i>
			</div>
		</div>
		<div class="drawer">
			<!-- <div class="title" slot="title">指令列表</div> -->
			<!-- <div class="version">当前版本{{version}} </div> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb forward tcp:12580 tcp:10086')">执行指令 adb forward tcp:12580 tcp:10086</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb version')">执行指令 adb version</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb shell')">执行指令adb shell</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb forward --list')">执行指令 adb forward --list</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('netstat -ano')">查看全部tcp</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb devices')">要查一下，是不是真的有多个设备或模拟器</el-button> -->
			<!-- <el-button class="lz-el-btn" type="primary" @click="ledOpen('adb kill-server')">释放端口</el-button> -->
			<el-button class="lz-el-btn" type="primary" @click="closeSocket()">断开印章socket</el-button>
			<!-- <el-button class="lz-el-btn" type="primary" @click="initTcp(tcp.PORT,tcp.HOST)">建立连接</el-button> -->
			<el-button class="lz-el-btn" type="primary" @click="signOut()">退出产测</el-button>
			<el-scrollbar style="height: calc(100vh - 220px);width: 100%;background-color: #f0f0f0;margin-bottom: 5px;">
				<div v-for="(item,index) in log" :key="index">{{item}}</div>
			</el-scrollbar>
			<el-button type="primary" @click="log=[]" size="mini">清空日志</el-button>
			<el-button type="primary" @click="writeLog" size="mini">写入数据</el-button>
		</div>
	</div>
	
</template>

<script>
	let that
	import {
		mapGetters,
		mapState
	} from 'vuex'
	const { ipcRenderer } = require("electron");
	export default {
		name: 'Layout',
		computed: {
			...mapGetters(['userInfo','size','version','appType']),
			...mapState({
				title: state => state.settings.title,
			}),
		},
		data(){
			return {
				logo:require('/static/images/Log.png'),
				log:[],
				drawer:{
					show:false
				}
				
			}
		},
		mounted() {
			that=this
			ipcRenderer.on('drawLog', function(event, res) { // 监听父页面
				that.log.push(res.data)
			});
		},
		methods: {
			minimizeFn(){
				ipcRenderer.send("new-setUp-window",{
					action:'min-app'
				});
			},
			closeFn(){
				ipcRenderer.send("new-setUp-window",{
					action:'close-app',//关闭窗口
				});
			},
			//向主窗口发送消息
			ledOpen(msg){
				let data = {
					action: 'sendCommand',
					data: msg
				}
				ipcRenderer.send("sendMessage",{
					action:'childMsg',
					data
				});
			},
			//退出产测
			signOut(){
				let data = {
					action: 'signOutTest',
					data: '退出产测'
				}
				ipcRenderer.send("sendMessage",{
					action:'childMsg',
					data
				});
			},
			closeSocket(){
				let data = {
					action: 'closeSocket',
					data: '断开印章socket'
				}
				ipcRenderer.send("sendMessage",{
					action:'childMsg',
					data
				});
			}
		}
	}
</script>

<style scoped="scoped" lang="scss">
	.subwindow{
		height: 100vh;
	}
	.app-sidebar{
		width: 100%;background-image: linear-gradient(#f0f0f0, #fff,#f0f0f0);overflow: hidden;-webkit-app-region: drag;
		display: flex;justify-content: space-between;align-items: center;padding: 10px 15px;box-sizing: border-box; 
		.has-logo{
			display: flex;align-items: center;
			.sidebar-title{
				display: inline-block;margin: 0;color: #000;
				font-weight: 600;margin-left: 10px;
				font-size: 14px;
				margin-right: 10px;
				max-width: 140px;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
		}
		.has-center{
			text-align: center;
		}
		.right-menu-btns{
			-webkit-app-region: no-drag;
			.icon{cursor: pointer;margin-left: 10px;}
		}
	}
	.drawer{
		padding: 10px;box-sizing: border-box;
		.lz-el-btn {
			width: 100%;margin: 0;margin-bottom: 10px;
		}
		.el-drawer__header{
			margin-bottom: 0;
		}
	}
</style>
